package com.situ.object.service.impl;


import com.situ.object.dao.TeacherDao;
import com.situ.object.dao.impl.TeacherDaoImpl;
import com.situ.object.entity.Teacher;
import com.situ.object.service.TeacherService;

import java.util.List;

public class TeacherServiceImpl implements TeacherService {

    private TeacherDao teacherDao = new TeacherDaoImpl();

    @Override
    public Teacher selectByTeacherName(String teacher_name) {
        return null;
    }

    @Override
    public int addTeacher(Teacher teacher) throws Exception {
        int i = 0;
        String teacherName = teacher.getTeacherName();
        String teacherPassword = teacher.getStudentPassword();
        String teacherPhone = teacher.getPhone();
        Teacher t = teacherDao.selectByTeacherName(teacherName);
        //1、教师名不能重复
        if (t != null){
            throw new Exception("教师账户已存在");
        }
        //2、密码在3~16位
        if (teacherPassword.length()<3||teacherPassword.length()>16){
            throw new Exception("教师密码必须在3~16位");
        }
        //3、电话必须11位
        if (teacherPhone.length() != 11){
            throw new Exception("教师电话必须11位");
        }

        i = teacherDao.addTeacher(teacher);
        return i;
    }

    @Override
    public int deleteTeacher(Integer id) {
        return teacherDao.deleteTeacher(id);
    }

    @Override
    public int deleteByName(String name) {
        return 0;
    }

    @Override
    public List<Teacher> selectAll() {
        System.out.println(teacherDao.selectAll());
        return teacherDao.selectAll();
    }

    @Override
    public int edit(Teacher teacher) throws Exception {
        return teacherDao.edit(teacher);
    }
}
